//
//  EmergencyTable.m
//  OperationPro
//
//  Created by yaxue wang on 2017/5/4.
//  Copyright © 2017年 展鸿科技. All rights reserved.
//

#import "EmergencyTable.h"
#import "EmergencyTableCell.h"
#import "EmergencyModel.h"
@implementation EmergencyTable

- (void)initView{
    [super initView];
    [self setShowNoDataNotice:@"暂无内容"];
    self.backgroundColor =BackColor;
    self.separatorStyle=UITableViewCellSeparatorStyleNone;
    self.showsVerticalScrollIndicator =NO;
    [self registerCell:[EmergencyTableCell class] withModel:[EmergencyModel class]];
    [self setDataWithUrl:@"message_showEmergencyNotify" andParam:nil];
    [self setTableActionType:CTableActionType_Both];
    [self loadData];
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.mainData.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    EmergencyModel *model = [self.mainData objectAtIndex:indexPath.row];
    CGSize labelsize = CGSizeZero;
    CGSize namesize = CGSizeZero;
    NSString *name =model.E_title;
    NSString *context =model.E_brief;
    
    
    if ([context isEqualToString:@""]) {
    }else
    {
        namesize=[name sizeWithFont:F(14) constrainedToSize:CGSizeMake(WindowWidth-66, 900)];
        labelsize = [context sizeWithFont:F(12) constrainedToSize:CGSizeMake(WindowWidth-66, 900)];
    }
    return MAX(labelsize.height+namesize.height+82 , 130);
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSString *cellID = [NSString stringWithFormat:@"Cell_%@", NSStringFromClass([EmergencyModel class])];
    EmergencyTableCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[EmergencyTableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    cell.selectionStyle=UITableViewCellSelectionStyleNone;
    
    EmergencyModel *model = [self.mainData objectAtIndex:indexPath.row];
    [cell setModel:model];
    
    return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    EmergencyModel *model = [self.mainData objectAtIndex:indexPath.row];
    if (self.CCellSelect) {
        self.CCellSelect(model.E_content);
    }
    
}

@end
